using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace MTRC.ODMS.Web.SOM.CodeSetup
{
    /// <summary>
    /// Author: XiaoChunhu
    /// DateTime: 2008-11-4
    /// Search data from database
    /// </summary>
    public partial class StationCodeList : BasePage_SOM
    {
        #region MenuID

        protected override string MenuID
        {
            get
            {
                return "M140820";//set the Menu
            }
        }

        #endregion

        #region Page Init And Load

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.ChangeLanguage += new ChangeLanguageEventHandler(SetLanguage_Click);//use function to set the language
        }

        #endregion

        #region page load and set the page lanuage

        //when the page load,these funtion will be run
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // add by dylan 20151030 for u275.1 
                this.grvData.PageSize = this.GridViewPageDefaultSize();
                SetLanguage();
            }
        }

        /// <summary>
        /// set the lanuage for the page
        /// </summary>
        private void SetLanguage()
        {
            this.lblStation.Text = this.GetLabel("SOM_Station", true);
            this.lblDescription.Text = this.GetLabel("SOM_Description", true);
            this.btnSearch.Text = this.GetLabel("COM_Search");
            this.btnAddNew.Text = this.GetLabel("SOM_AddNewAssetLoanItem");
            this.chkVoid.Text = this.GetLabel("SOM_Voided");
            this.lblDisplay.Text = this.GetLabel("COM_Show", true);

            BindStation();//when the page load, this funtion will to bind some data on the Location
            BindData();//when the page load, this funtion will to bind some data on the grvData
        }

        //when you chanage the language,this function will be run
        void SetLanguage_Click(object sender, EventArgs e)
        {
            SetLanguage();
        }

        #endregion

        #region bind some data

        /// <summary>
        /// get the location and bind on the control
        /// </summary>
        private void BindStation()
        {
            //get the location code by the LangCode
            DataTable dt = MTRC.ODMS.DAL.SOM.CodeSetup.CDLocation.GetLocation(this.LangCode);
            BindListControl(this.ddlStation, "LocationID", "LocationCode", dt, true);//bind data for the control
            dt.Dispose();
            dt = null;
        }

        /// <summary>
        /// get the datatable and bind on the grvData
        /// </summary>
        private void BindData()
        {
            //get the datatable by the condition
            DataTable dt = MTRC.ODMS.DAL.SOM.CodeSetup.CDStation.GetStationByCondition(this.LangCode, int.Parse(this.ddlStation.SelectedValue), txtDescription.Text.Trim(), chkVoid.Checked);
            this.grvData.DataSource = dt.DefaultView;//bind the data on the grvData
            this.grvData.DataBind();
            dt.Dispose();
            dt = null;
        }

        /// <summary>
        /// where you trun page,this function will be run 
        /// </summary>
        protected void grvData_NeedDataBind()
        {
            BindData();
        }

        /// <summary>
        /// click the rows and send some to the CleanEstablishmentEntry page
        /// </summary>
        protected void grvData_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //click the rows and send CleanPassScoreid to the Edit page
                ((HyperLink)e.Row.Cells[3].FindControl("hypEdit")).NavigateUrl = "StationCodeEntry.aspx?StationID=" + this.grvData.DataKeys[e.Row.RowIndex]["StationID"].ToString();//click the rows and send StationID to the StationCodeEntry page
                ((HyperLink)e.Row.Cells[3].FindControl("hypEdit")).ToolTip = this.GetLabel("SOM_StationEdit");//get the message
            }
        }

        #endregion

        #region some event

        //when you want to find some data for you need,you can click the "Search"
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }

        //when you want to create new data,you can click the "Add New"
        protected void btnAddNew_Click(object sender, EventArgs e)
        {
            this.Response.Redirect("StationCodeEntry.aspx");
        }

        #endregion
    }
}
